package com.woniuxy.three.pms.room.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.three.pms.bean.RoomBean;
import com.woniuxy.three.pms.dao.RoomBeanMapper;
import com.woniuxy.three.pms.room.service.IRoomService;

/**
* @ProjectName: PMS
* @Package: com.woniuxy.three.pms.room.service.impl.RoomServiceImpl
* @ClassName: IRoomService 
* @Author:  subai-dhl
* @Description: 房间管理模块 
* @Date: 2019/6/20 16:04 
* @Version: 1.0 版本
* @See：参考版本
*/
@Service
public class RoomServiceImpl implements IRoomService{

	
	
	@Autowired
	private RoomBeanMapper RoomDao;
	
	/**
	* @Method findById 
	* @Author subai-dhl 
	* @Version 1.0
	* @Description 通过房间id查询房间所有信息
	* @Param: roomId 房间id
	* @Return RoomBean
	* @Exception 
	* @Date 2019/6/20 16:12
	*/
	@Override
	public RoomBean findById(Integer roomId) {
		RoomBean room = null;
		if(roomId!=null) {
			room = RoomDao.selectByPrimaryKey(roomId);
		}
		return room;
	}

	/**
	 * @Method findByType 
	 * @Author subai-dhl 
	 * @Version 1.0
	 * @Description 通过房间类型查询房间并分页
	 * @param roomType 房间类型
	 * @param pageNo 分页页码
	 * @param PageSize 每页显示数量
	 * @param hotalId 酒店id
	 * @param RoomStatus 房间状态
	 * @return PageInfo
	 * @Date 2019/6/20 16:20
	 */
	@Override
	public PageInfo<RoomBean> findByType(Integer roomType, Integer RoomStatus, Integer pageNo, Integer PageSize,
			Integer hotalId) {
		PageHelper.startPage(pageNo, PageSize);
		List<RoomBean> list = RoomDao.findRoomsByCondition(roomType, RoomStatus, hotalId);
		System.out.println(list);
		PageInfo<RoomBean> page = new PageInfo<RoomBean>(list);
		return page;
		
	}

	/**
	 * @Method findByRoomNumber
	 * @Author subai-dhl
	 * @Description 通过房间号查询房间信息
	 * @Version 1.0
	 * @param RoomNumber
	 * @param hotalId
	 * @return RoomBean
	 * @Date 2019/6/20 16:25
	 */
	@Override
	public RoomBean findByRoomNumber(String RoomNumber, Integer hotalId) {
		RoomBean room = RoomDao.findByRoomNumber(RoomNumber, hotalId);
		return room;
	}

	/**
	 * @Method addRoom
	 * @Author subai-dhl
	 * @Description 添加房间
	 * @Version 1.0
	 * @param room
	 * @return boolean 
	 * @Date 2019/6/20 16:37
	 */
	@Override
	public boolean addRoom(RoomBean room) {
		int number = 0;
		number = RoomDao.insert(room);
		if(number>0) {
			return true;
		}
		return false;
	}

	/**
	 * @Method changeRoom
	 * @Author subai-dhl
	 * @Description 修改房间内容   
	 * @Version 1.0
	 * @param room
	 * @return
	 * @Date 2019/6/20 16:48
	 */
	@Override
	public boolean changeRoom(RoomBean room) {
		int number = 0;
		number = RoomDao.updateByPrimaryKeySelective(room);
		if(number>0) {
			return true;
		}
		return false;
	}

	
	
	/**
	 * @Method findRoomNumberByRoomType
	 * @Author subai-dhl
	 * @Description 查询某类房间可住数量，除去已删除状态的房间 （效率慢，少用）  
	 * @Version 1.0
	 * @param roomTypeId
	 * @return 该类房间的总数量，包括除已删除状态外的所有状态
	 * @Date 2019/6/20 16:56
	 */
	@Override
	public int findRoomNumberByRoomType(Integer roomTypeId) {
		int number = 0;
		if(roomTypeId!=null) {
			number = RoomDao.findRoomNumberByRoomType(roomTypeId);
		}
		return number;
	}

}
